app
.controller('formSelfCtrl', ['$scope', '$http', FormSelfController]);
function FormSelfController($scope, $http){
	$scope.changeValueMap = function(field) {
		
		if(field == 'authorizationTime' || field == 'updateCycle') {
			
		    var authorizationTime = $scope.valueMap['authorizationTime']; // 授权时间
		    var updateCycle = parseFloat($scope.valueMap['updateCycle']); // 更新周期

		    if(authorizationTime
		        && (updateCycle || updateCycle == 0)) {
		        // 到期日期 = 授权日期 + 有效天数
		        var nextAuthorizationTime = new Date(Date.parse(authorizationTime));

		        nextAuthorizationTime.setDate(nextAuthorizationTime.getDate() + updateCycle);
				$scope.valueMap['nextAuthorizationTime'] = formatDate(nextAuthorizationTime);
		    }
		}
	}
}

function formatDate(date) {
    var year = date.getFullYear();
    var month = ('0' + (date.getMonth() + 1)).slice(-2);
    var day = ('0' + date.getDate()).slice(-2);
    var hours = ('0' + date.getHours()).slice(-2);
    var minutes = ('0' + date.getMinutes()).slice(-2);
    var seconds = ('0' + date.getSeconds()).slice(-2);

    return year + '-' + month + '-' + day;
}

